//
//  ContactTableViewCell.m
//  BGM
//
//  Created by liuqin on 2018/11/26.
//  Copyright © 2018年 com.alirtc.demo. All rights reserved.
//

#import "ContactTableViewCell.h"
#import "Common.h"
#import "UIImageView+WebCache.h"


@interface ContactTableViewCell ()

@property (nonatomic, strong)BGMuserFriendClass *friend;

@end


@implementation ContactTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 6, 40, 40)];
        [self.headImage setImage:[UIImage imageNamed:@"headImage"]];
        self.headImage.layer.cornerRadius = 20;
        self.headImage.layer.masksToBounds = YES;
        [self addSubview:self.headImage];
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, 300, 52)];
        self.nameLabel.textColor = bgmmainColor;
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        self.nameLabel.text = @"安涛";
        [self addSubview:self.nameLabel];
        
        self.addBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW-80, 10, 50, 30)];
        self.addBtn.backgroundColor = bgmyelloeColor;
        [self.addBtn setTitle:@"邀请" forState:UIControlStateNormal];
        [self.addBtn setTitleColor:bgmmainColor forState:UIControlStateNormal];
        
        [self.addBtn setTitle:@"等待" forState:UIControlStateSelected];
        [self.addBtn setTitleColor:bgmsmallColor forState:UIControlStateSelected];
        
        self.addBtn.layer.cornerRadius = 15;
        self.addBtn.layer.masksToBounds = YES;
        self.addBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.addBtn];
        [self.addBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        self.addBtn.hidden = YES;

        
    }
    return self;
}
- (void)clickBtn:(UIButton *)btn{
    [self.contactDelegate clickOtherFriend:self.friend.spareOne indexPath:self.index];
}


- (void)setFriendValue:(BGMuserFriendClass *)bgmfriend isInvit:(NSString *)isInvit row:(NSIndexPath *)index{
    self.friend = bgmfriend;
    if ([bgmfriend.type isEqualToString:@"1"]) { //好友
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:bgmfriend.headImage] placeholderImage:[UIImage imageNamed:@"headImage"]];
        self.addBtn.hidden = YES;
    }else{
        [self.headImage setImage:[UIImage imageNamed:@"headImage2"]];
        
        self.addBtn.hidden = NO;
        self.addBtn.tag = (int)index.row;
        self.index = index;
        if([isInvit isEqualToString:@"1"]){
            self.addBtn.selected = YES;
            self.addBtn.enabled = NO;
            self.addBtn.backgroundColor = bgmColor(211, 211, 211);
        }else{
            self.addBtn.selected = NO;
            self.addBtn.enabled = YES;
            self.addBtn.backgroundColor = bgmyelloeColor;


        }
    }
    self.nameLabel.text = bgmfriend.name;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
